﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Utils;
namespace UI.ModEmployee
{
    public partial class EmpContractList : System.Web.UI.Page
    {
        EmpContractBiz empContractBiz = new EmpContractBiz();
        EmployeeBiz employeeBiz = new EmployeeBiz();
        string empCode = "";
        string bTm = "";
        string eTm = "";
        string statu = "";
        string timeType = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["EmpCode"] != null) empCode = Request.Params["EmpCode"].ToString().Trim();
            if (Request.Params["BTime"] != null) bTm = Request.Params["BTime"].ToString().Trim();
            if (Request.Params["ETime"] != null) eTm = Request.Params["ETime"].ToString().Trim();
            if (Request.Params["Statu"] != null) statu = Request.Params["Statu"].ToString().Trim();
            if (Request.Params["TimeType"] != null) timeType = Request.Params["TimeType"].ToString().Trim();

            if (!IsPostBack)
            {
                DateTime dTime = System.DateTime.Now;
                btnAdd.Attributes.Add("onclick", "javascript:ShowLink('EmpContractAdd.aspx',800,550);");
                if (empCode != "")
                {
                    txtSerWord.Text = empCode;
                    if (bTm != "") txtBtime.Text = bTm;
                    if (eTm != "") txtEtime.Text = eTm;
                    BondGvList(empCode, bTm, eTm, statu, timeType);
                }
                else
                {
                    //display to End info
                    BondGvList("", dTime.AddDays(-10).ToString("yyyy-MM-dd"), System.DateTime.Now.AddDays(5).ToString("yyyy-MM-dd"), "Y", "EndTime");

                }
                //more than 10 days  delete it
                int thisDay = dTime.Day;
                if (thisDay == 1 || thisDay == 5 || thisDay == 10 || thisDay == 15 || thisDay == 20 || thisDay == 25 || thisDay == 30)
                    empContractBiz.UpdateToEnd();


            }
        }
        protected void btnEmSearch_Click(object sender, EventArgs e)
        {
            string serWord = txtSerWord.Text.Trim();
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();
            string statu = ddlStatu.SelectedValue;
            string timeType = ddlTimeType.SelectedValue;
      
            if (serWord == "" && bTime == "" && eTime == "")
            {
                bTime = System.DateTime.Now.AddMonths(-2).ToString("yyyy-MM-dd");
                eTime = System.DateTime.Now.ToString("yyyy-MM-dd");
            }
            if (StringUtility.GetDiffDays(bTime, eTime) > XmlUtility.GetNumFormConfig("daysOfSearch"))
            {
                JSUtility.Alert(this, "查询日期间隔不能大于" + XmlUtility.GetNumFormConfig("daysOfSearch") + "天！");
                return;
            }
            
            BondGvList(serWord, bTime, eTime, statu, timeType);

        }

        protected void BondGvList(string serWord, string bTime, string eTime, string statu, string timeType)
        {
            DataTable dt = empContractBiz.GetLists(serWord, bTime, eTime, statu, timeType);
            if (dt.Rows.Count > 0)
            {

                gvList.DataSource = dt;
                gvList.DataBind();
            }
            else
            {
                if (empCode == "")
                    JSUtility.Alert(this, "无符合条件的数据");
            }
        }
        protected void btnClear_Click(object sender, EventArgs e)
        {
            txtBtime.Text = "";
            txtEtime.Text = "";
            txtSerWord.Text = "";
        }

        protected void btnExcel_Click(object sender, EventArgs e)
        {
            string serWord = txtSerWord.Text.Trim();
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();
            string statu = ddlStatu.SelectedValue;
            string timeType = ddlTimeType.SelectedValue;
            ExcelUtility.ExportDsToXls(this, empContractBiz.GetLists(serWord, bTime, eTime, statu, timeType), "EmpContract.xls");
            //ExcelUtility.GridViewToExcel(gvList, "EmpContract.xls");
        }

        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].Visible = false;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#F3F8F8'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
            }
        }



    }
}